<template>
   <van-cell @click="getArticle">
      <!-- 标题区域的插槽 -->
      <template #title>
        <div class="title-box">
          <!-- 标题 -->
          <span class="biaoti" v-if="img.length !==3">{{ title }}</span>
          <span class="biaoti2" v-if="img.length ===3">{{ title }}</span>
          <!-- 单张图片 -->
          <img
            :src="img[0]"
            alt=""
            class="thumb thumb1"
            v-if="img.length === 1 ||img.length === 2"
            v-lazy="img[0]"
          />
        </div>
        <!-- 两张图片 -->
        <!-- <div class="thumb-box" v-if="img.length === 2">
          <img
            :src="item"
            alt=""
            class="thumb"
            v-for="item in img"
            :key="item.index"
          />
        </div> -->
        <!-- 三张图片 -->
          <div class="thumb-box" v-if="img.length === 3">
          <img
            :src="item"
            alt=""
            class="thumb"
            v-for="item in img"
            :key="item.index"
            v-lazy="item"
          />
        </div>
      </template>
      <!-- label 区域的插槽 -->
      <template #label>
        <div class="label-box">
          <span class="author"> 作者 {{ author }}</span>
          <span>{{ amcount }}评论</span>
          <span> &nbsp;&nbsp;发布日期: {{ new Date(time).toLocaleString() }}</span>
          <!-- 关闭按钮 -->
          <van-icon name="cross" />
        </div>
      </template>
    </van-cell>
</template>

<script>
import { mapState } from 'vuex'
// import { replyList } from '@/api/api'
export default {
    data(){
        return{
            // times:parseInt(this.time)
          
        }
    },
    props:{
        id: {
          type: String
        },
        author: {
            type: [Number,String],
            default: '吴彦祖'
        },
        title:{
            type: String,
            default: ''
        },
        amcount:{
            type: Number,
            default: 0
        },
        img:{
            default:'https://www.bing.com/th/id/OGC.7358f4766f5d9772dd78801d41f983fc?pid=1.7&rurl=https%3a%2f%2fpic1.zhimg.com%2fv2-8bb7134349fe776844ed1de000af4de0_b.gif&ehk=l0nDsBOMRNW3Hz3AlBoxPzSo0r9jqZDX7S3J6KTB2qw%3d'
        },
        time:{
            default: new Date()
        }
    },
    computed:{
      ...mapState(['author_id'])
    },
    methods:{
     async getArticle(){
       let { uid:user_id } = localStorage
      const { data:res } = await  this.$http.post('/api/get_article_detail',{
          article_id: this.id,
          user_id
        })
        this.$store.commit('getArticleList',res.data)
        localStorage.setItem('articleList2',JSON.stringify(res.data))
        this.$router.push('/article')
      }
    }
   
}
</script>

<style lang="less" scoped>

.biaoti,.biaoti2{
  display: -webkit-box;
  width: 230px;
  overflow: hidden;
  white-space: wrap;
  text-overflow: ellipsis;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.biaoti2{
  width: 330px;
}
.author{
  display: inline-block;
  width: 100px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.label-box {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.thumb {
  // 矩形黄金比例：0.618
  width: 113px;
  height: 70px;
  background-color: #f8f8f8;
  object-fit: cover;
}
.thumb1{
  float: right;
}
.title-box {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.thumb-box {
  display: flex;
  justify-content: space-between;
}
</style>